package cn.mw.cmdb.view;

import cn.mw.cmdb.anno.CMDBHeader;
import cn.mw.cmdb.entity.ModelInfo;
import cn.mw.cmdb.entity.PropertyTypeInt;
import cn.mw.cmdb.entity.PropertyTypeTime;
import cn.mw.microMonitorCommon.util.DateUtils;
import lombok.Data;

import java.util.Date;

@Data
public class StaticsViewModel {
    @CMDBHeader(name = "ID")
    private String id;

    @CMDBHeader(name = "名称")
    private String modelName;

    @CMDBHeader(name = "数量", propertyTypeId = PropertyTypeInt.ID)
    private Long instanceNum;

    @CMDBHeader(name = "类型")
    private String modelType;

    @CMDBHeader(name = "描述")
    private String modelDesc;

    @CMDBHeader(name = "创建人")
    private String creater;

    @CMDBHeader(name = "创建时间", propertyTypeId = PropertyTypeTime.ID)
    private String createTime;
    public void extractFrom(ModelInfo modelInfo){
        this.id = modelInfo.getId();
        this.modelName = modelInfo.getModelName();
        this.modelType = modelInfo.getModelType().getName();
        this.modelDesc = modelInfo.getSpec();
        this.createTime = modelInfo.getCreateTime()!=null? DateUtils.format(modelInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss"):"";
    }
}
